package com.red.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.red.entity.Account;
import com.red.entity.ProductUnit;
import com.red.result.Result;
import com.red.service.ProductUnitService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/product/unit")
public class ProductUnitController {
    @Autowired
    private ProductUnitService productUnitService;

    @ApiOperation("根据条件查询单位分类")
    @ApiImplicitParam(name = "name",value = "单位名称")
    @GetMapping("/select")
    public Result findAll(String name){
        return new Result(
                productUnitService.list(
                        new QueryWrapper<ProductUnit>()
                                .like(name!=null,"name",name)
                )
        );
    }

    @ApiOperation("添加单位分类")
    @PostMapping("/save")
    public Result save(ProductUnit productUnit){
        return new Result(productUnitService.save(productUnit));
    }

    @ApiOperation("修改单位分类")
    @PutMapping("/update")
    public Result update(ProductUnit productUnit){
        return new Result(productUnitService.updateById(productUnit));
    }

    @ApiOperation("删除单位分类")
    @DeleteMapping("/delete")
    public Result delete(Integer id){
        return  new Result(productUnitService.removeById(id));
    }
}
